package com.pocketsweet.ui.uilib;

import com.pocketsweet.R;

import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

public class LoadingDailog extends Dialog {
    private TextView tipTextView;
    private TextView tvProgressText;
    Context context;

    public LoadingDailog(Context context) {
        super(context);
        this.context = context;
        init(context);
    }

    public LoadingDailog(Context context, int theme) {
        super(context, theme);
        this.context = context;
        init(context);
    }

    private void init(Context context) {
        // main.xml中的ImageView
        LayoutInflater inflater = LayoutInflater.from(context);
        View v = inflater.inflate(R.layout.view_progress_dialoog, null);// 得到加载view
        ImageView spaceshipImage = (ImageView) v
                .findViewById(R.id.ivDialogRefreshIcon);
        tipTextView = (TextView) v.findViewById(R.id.tvDialogText);// 提示文字
        tvProgressText = (TextView) v.findViewById(R.id.tvProgressText);// 进度提示文字
        // 加载动画
        Animation hyperspaceJumpAnimation = AnimationUtils.loadAnimation(
                context, R.anim.loading_animation);
        // 使用ImageView显示动画
        spaceshipImage.startAnimation(hyperspaceJumpAnimation);
        super.setContentView(v);
    }

    @Override
    public void setContentView(View view) {
    }

    public void setText(String msg) {
        tipTextView.setText(msg);// 设置加载信息
    }

    public void setProgressText(String msg) {
        tvProgressText.setText(msg);// 设置加载信息
    }

    @Override
    public void dismiss() {
        if (context != null && !((Activity) context).isFinishing()) {
            super.dismiss();    //调用超类对应方法
        }
    }
}
